/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package meteocal.business.entity;

import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.Lob;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import meteocal.business.security.entity.User;

/**
 *
 * @author luana
 */
@Entity
@Table(name = "EVENT")
@NamedQueries({
    @NamedQuery(name = "Event.findAll", query = "SELECT e FROM Event e"),
    @NamedQuery(name = "Event.findByIdEvent", query = "SELECT e FROM Event e WHERE e.idEvent = :idEvent"),
    @NamedQuery(name = "Event.findByStartingDate", query = "SELECT e FROM Event e WHERE e.starting_date = :starting_date"),
    @NamedQuery(name = "Event.findByEndingDate", query = "SELECT e FROM Event e WHERE e.ending_date = :ending_date"),
    @NamedQuery(name = "Event.findByEndingTime", query = "SELECT e FROM Event e WHERE e.endingTime = :endingTime"),
    @NamedQuery(name = "Event.findByName", query = "SELECT e FROM Event e WHERE e.name = :name"),
    @NamedQuery(name = "Event.findByPlace", query = "SELECT e FROM Event e WHERE e.place = :place"),
    @NamedQuery(name = "Event.findByStartingTime", query = "SELECT e FROM Event e WHERE e.startingTime = :startingTime"),
    @NamedQuery(name = "Event.deleteByIdEvent", query = "DELETE FROM Event e WHERE e.idEvent = :idEvent"),
    @NamedQuery(name = "Event.findByUser", query = "SELECT e FROM Event e WHERE e.creator = :creator" )    
})

public class Event implements Serializable {
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "idEvent")
    private Collection<Notification> notificationCollection;
    
        private static final long serialVersionUID = 1L;

   
    
    public static final String FIND_EVENT_BY_DATE = "Event.findByStartingDate";
    public static final String DELETE_EVENT = "Event.deleteByIdEvent";
    public static final String FIND_BY_USER = "Event.findByUser";
    public static final String FIND_BY_IDEVENT= "Event.findByIdEvent";
    
   
       
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "ID_EVENT")
    private Integer idEvent;
    
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 45)
    @Column(name = "NAME")
    private String name;
    
    @Lob
    @Size(max = 2147483647)
    @Column(name = "DESCRIPTION")
    private String description;
    
    
    @Basic(optional = false)
    @NotNull
    @Column(name = "STARTING_DATE")
    @Temporal(TemporalType.DATE)
    private Date starting_date;
    
    @Basic(optional = false)
    @NotNull
    @Column(name = "ENDING_DATE")
    @Temporal(TemporalType.DATE)
    private Date ending_date;
    
    @Basic(optional = false)
    @NotNull
    @Column(name = "STARTING_TIME")
    @Temporal(TemporalType.TIME)
    private Date startingTime;
   
    
    @Basic(optional = false)
    @NotNull
    @Column(name = "ENDING_TIME")
    @Temporal(TemporalType.TIME)
    private Date endingTime;
        
    
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 45)
    @Column(name = "PLACE")
    private String place;
    
    @Basic(optional = false)
    @NotNull
    @Column(name = "TYPE")
    private boolean type;
    
    
    /**
     * We made confusion on binary/boolean types; I set the privacy level to boolean indicating 
     * if public (true) or private (false)
     */
    @Basic(optional = false)
    @NotNull
    @Column(name = "PRIVACY_LEVEL")
    private boolean privacyLevel;
    
  
    @JoinTable(name = "PARTICIPANTS", joinColumns = {
        @JoinColumn(name = "ID_EVENT")}, inverseJoinColumns = {
        @JoinColumn(name = "USER")})
    @ManyToMany
    private Collection<User> partecipatingUsers;

     @JoinTable(name = "PENDING", joinColumns = {
        @JoinColumn(name = "ID_EVENT", referencedColumnName = "ID_EVENT")}, inverseJoinColumns = {
        @JoinColumn(name = "USER", referencedColumnName = "USERNAME")})
    @ManyToMany
    private Collection<User> pendingUsers;
     
       
    @JoinColumn(name = "CREATOR", referencedColumnName = "USERNAME")
    @ManyToOne(optional = false)
    private User creator;
    
    @JoinColumn(name = "EXPECTED_WEATHER", referencedColumnName = "ID_WEATHER")
    @ManyToOne(optional = false)
    private Weather expectedWeather;
    
    public Event() {
    }

    public Event(Integer idEvent) {
        this.idEvent = idEvent;
    }

    public Event(Integer idEvent, String name, String description, Date starting_date, Date ending_date, Date startingTime, Date endingTime, String place, boolean type, boolean privacyLevel, Collection<User> participants, Collection<User> pending, User creator, Weather expectedWeather) {
        this.idEvent = idEvent;
        this.name = name;
        this.description = description;
        this.starting_date = starting_date;
        this.ending_date = ending_date;
        this.startingTime = startingTime;
        this.endingTime = endingTime;
        this.place = place;
        this.type = type;
        this.privacyLevel = privacyLevel;
        this.partecipatingUsers = participants;
        this.pendingUsers=pending;
        this.creator = creator;
        this.expectedWeather = expectedWeather;
    }

    

    public Collection<User> getParticipants() {
        return partecipatingUsers;
    }

    public void setParticipants(Collection<User> participants) {
        this.partecipatingUsers = participants;
    }

    public Collection<User> getPendingUsers() {
        return pendingUsers;
    }

    public void setPendingUsers(Collection<User> userCollection) {
        this.pendingUsers = userCollection;
    }
   
    
    public Integer getIdEvent() {
        return idEvent;
    }

    public void setIdEvent(Integer idEvent) {
        this.idEvent = idEvent;
    }

    public Date getStarting_date() {
        return starting_date;
    }

    public void setStarting_date(Date starting_date) {
        this.starting_date = starting_date;
    }

    public Date getEnding_date() {
        return ending_date;
    }

    public void setEnding_date(Date ending_date) {
        this.ending_date = ending_date;
    }

    
    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public Date getEndingTime() {
        return endingTime;
    }

    public void setEndingTime(Date endingTime) {
        this.endingTime = endingTime;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPlace() {
        return place;
    }

    public void setPlace(String place) {
        this.place = place;
    }

    public boolean getPrivacyLevel() {
        return privacyLevel;
    }

    public void setPrivacyLevel(boolean privacyLevel) {
        this.privacyLevel = privacyLevel;
    }

    public Date getStartingTime() {
        return startingTime;
    }

    public void setStartingTime(Date startingTime) {
        this.startingTime = startingTime;
    }

    
    public User getCreator() {
        return creator;
    }

    public void setCreator(User creator) {
        this.creator = creator;
    }

    public Weather getExpectedWeather() {
        return expectedWeather;
    }

    public void setExpectedWeather(Weather expectedWeather) {
        this.expectedWeather = expectedWeather;
    }

    public boolean getType() {
        return type;
    }

    public void setType(boolean type) {
        this.type = type;
    }

    public Collection<Notification> getNotificationCollection() {
        return notificationCollection;
    }

    public void setNotificationCollection(Collection<Notification> notificationCollection) {
        this.notificationCollection = notificationCollection;
    }

   
    
}
